﻿/*
·´`·.¸.»------------------------------------------------------------ë·´`·.¸.»
        File: ImageEditWindow.cs
        Project: Themaopdracht 7
        Author: Felix Mann

        Description:
        This form is the MDIClient Window that contains an image and
        the history of filters that have been run on an image. The 
        class itself does not really do a lot of stuff, ExtendedForm 
        calls the actual filters.
·´`·.¸.»------------------------------------------------------------ë·´`·.¸.»
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace THO7_Team8
{
    public partial class ImageEditWindow : Form
    {
        private Bitmap originalPicture;
        private List<Bitmap> imageList = new List<Bitmap>();
        private List<String> operationList = new List<String>();
        public delegate void AddListItem();
        public AddListItem myDelegate;
        public ImageEditWindow(Bitmap InputImage)
        {
            InitializeComponent();
            imageList.Add(InputImage);
            thumbnailList.Images.Add(InputImage);
            operationList.Add("Original");
            listView1.LargeImageList = thumbnailList;
            listView1.Items.Add("Original", 0);
            if (InputImage != null)
            {
                this.originalPicture = InputImage;
                pictureBox1.Image = InputImage;
            }
        }
        public Bitmap getCurrent()
        {
            return (Bitmap)pictureBox1.Image;
        }
        public PictureBox getPictureBox()
        {
            return this.pictureBox1;
        }
        public void addEditedPicture(Bitmap newImage, String operationName)
        {
            imageList.Add(newImage);
            operationList.Add(operationName);

            thumbnailList.Images.Add(newImage);
            listView1.Items.Add(operationName, thumbnailList.Images.Count - 1);
            //listView1.Items.Add(operationName, (imageList.Images.Count - 1));
            pictureBox1.Image = imageList[thumbnailList.Images.Count - 1];
            listView1.FocusedItem = listView1.Items[thumbnailList.Images.Count - 1];
            Console.WriteLine(thumbnailList.Images.Count);
        }

        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                pictureBox1.Image = imageList[listView1.FocusedItem.ImageIndex];
            }
            catch (NullReferenceException nre)
            {
                Console.WriteLine(
                 "\nThere is NO item with focus. Do nothing.\n" +
                 nre.Message);
            } 
            
            //pictureBox1.Image = imageList.Images[listView1.SelectedItems[0].ImageIndex];
            //Console.WriteLine(listView1.FocusedItem.ImageIndex);
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            Form myNoiseForm = new FilterTest(thumbnailList, operationList, imageList);
            myNoiseForm.Owner = this;
            myNoiseForm.Show();
        }
    }
}
